import pymysql
from pyecharts.charts import Pie
from pyecharts import  options

# 创建数据库连接
# locahost 127.0.0.1 都是本机
db = pymysql.connect(
    host="localhost",
    port=3306,
    user="root",
    database="crawlerdemo",
    password="HCXHCX",
    charset="utf8"
)
cursor = db.cursor()
# 用来查找岗位数量最多的五个城市
sql = ("select job_place,count(job_id) from job group by job_place "
       "order by count(job_id) desc limit 5")
try:
    cursor.execute(sql)
    res = cursor.fetchall()
    Pie = Pie()
    # [(”类型1“，30),(”类型2“，40),......]
    Pie.add("单位/个",res)
    Pie.set_global_opts(title_opts=options.TitleOpts(title="岗位数量最多的五个城市"))
    Pie.render("pienum.html")
except:
    print("查询出错啦")
